﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

#include "GcmpGUiBaseImpl.h"
#include "ICommandButtonDefinition.h"
#include "CommandControlDefinition.h"

namespace gcmp
{
    class ControlDefinitionChangeEvent;
    class IControlDefinitionChangeEvent;
    class CommandControlDefinition;
    // 命令项，对应一个按钮。
    class GCMP_GUI_BASE_IMPL_EXPORT CommandButtonDefinition : public ICommandButtonDefinition
    {
    public:
        CommandButtonDefinition(const std::wstring& id, const std::wstring& caption, const std::wstring& tooltip, const std::wstring& commandId, const std::wstring& iconPath, ButtonStyle buttonStyle);
        virtual ~CommandButtonDefinition();

    public:
        virtual std::wstring GetIconPath() const override{ return m_iconPath; }
        virtual bool SetIconPath(const std::wstring& iconPath) override;

        virtual ButtonStyle GetButtonStyle() const override { return m_buttonStyle; }
        virtual bool SetButtonStyle(ButtonStyle style) override;

        virtual bool SetCaption(const std::wstring& caption) override;
        virtual std::wstring GetCaption() const override { return m_pControlDefinition->GetCaption(); }

       virtual std::wstring GetCommandId() const override { return m_pControlDefinition->GetCommandId(); }
       virtual void SetIsChecked(bool isChecked) override;
       virtual bool IsChecked() const override { return m_pControlDefinition->IsChecked(); }
       IControlDefinitionChangeEvent* GetControlDefinitionChangeEvent() const;
    public:
        virtual std::wstring GetId() const override { return m_pControlDefinition->GetId(); }
        virtual std::wstring GetTooltip() const override { return m_pControlDefinition->GetTooltip(); }
        virtual bool IsVisible() const override { return m_pControlDefinition->IsVisible(); }
        virtual bool IsEnabled() const override { return m_pControlDefinition->IsEnabled(); }
        virtual ControlDefinitionType GetType() const override { return ControlDefinitionType::CommandButton; }

    private:
        OwnerPtr<CommandControlDefinition> m_pControlDefinition;
        std::wstring m_iconPath; // 图标路径。
        ButtonStyle m_buttonStyle;

        // 通知使用该定义的控件的事件
        OwnerPtr<ControlDefinitionChangeEvent> m_pDefinitionChangeEvent;
    };
}
